<?php 
		//-------------------------------------------------------------------------------------------
		//----------------------------- DETAIL DE LA FACTURE  --------------------------------------
		//-------------------------------------------------------------------------------------------
		


		//Affichage du Total
		

//Affichage du detail forfait, options et equipement
for($n=0;$n<count($facture);$n++)
	{
		if($n>=1){}
?>
		<table width="560" align="left" >
        <tr >
        <td width="460" align="left"><b>Services et produits</b>
		<?php if(date("m/Y",$date_souscription[$n]) == date("m/Y",$debut_mois_prec) and $facture_faite[$n]==0)
			{?><small>Souscription au <?php echo date("d/m/Y",$date_souscription[$n]);?></small><?php }?>
            </td>
        <td width="100" align="center"><b>Montant € HT</b></td>
        </tr>
<?php
			echo "<tr><td>";
			echo "Pour la ligne ".$facture[$n]['numero_ligne'].", ".$facture[$n]['utilisateur'];
			echo "<br>Abonnements, forfaits et options :";
			echo "</td><td></td></tr>";
			
			//Affichage de l'Equipement
			if($tab_mobile[$n]['nom']!="Pas d'Equipement")
					{
			echo "<tr><td>";
			if($tab_mobile[$n]['reduction'])
			{			
				echo $tab_mobile[$n]['nom']." (-".$tab_mobile[$n]['reduction']."%)";
			}else{
				echo $tab_mobile[$n]['nom'];
			}
			echo "</td><td align='right'>";
			echo $tab_mobile[$n]['prix'];
			echo "</td></tr>";
					}
					
			//Affichage du Forfait
			
			echo "<tr><td>";
			if($tab_forfait[$n]['remise'])
				{
					echo htmlentities($tab_forfait[$n]['nom'])." (-".$tab_forfait[$n]['remise']."%)";
				}else{
					echo htmlentities($tab_forfait[$n]['nom']);
				}
			if(date("m/Y",$date_souscription[$n]) == date("m/Y",$debut_mois_prec) and $facture_faite[$n]==0)
			{?>
            <small> du <?php echo date("d/m/Y",$date_souscription[$n]);?> au <?php echo date("t/m/Y",$date_souscription[$n]);?></small><?php 
			}
			echo "</td><td align='right'>";
			echo number_format($total_forfait[$n],2);
			echo "</td></tr>";
			
			
			//Affichage du Forfait plein
			if(date("m/Y",$date_souscription[$n]) == date("m/Y",$debut_mois_prec) and $facture_faite[$n]==0)
			{
			if($tab_forfait[$n]['remise'])
				{
				echo "<tr><td>";
				echo htmlentities($tab_forfait[$n]['nom'])." ".date("m/Y")." (-".$tab_forfait[$n]['remise']."%)";
				echo "</td><td align='right'>";
				}else{
				echo "<tr><td>";
				echo htmlentities($tab_forfait[$n]['nom'])." ".date("m/Y");
				echo "</td><td align='right'>";
				}
			echo number_format($total_forfait_plein[$n],2);
			echo "</td></tr>";
			}

			//Affichage des Options 
			if(isset($tab_option[$n]))
			{
			for($i=0;$i<count($tab_option[$n]);$i++)
					{
			echo "<tr><td>";
			if($tab_option[$n][$i]['reduction'])
				{
			echo $tab_option[$n][$i]['nom']." (-".$tab_option[$n][$i]['reduction']."%)";
				}else{
			echo $tab_option[$n][$i]['nom'];
				}
			if(date("m/Y",$date_souscription[$n]) == date("m/Y",$debut_mois_prec) and $facture_faite[$n]==0)
			{?>
            <small> du <?php echo date("d/m/Y",$date_souscription[$n]);?> au <?php echo date("t/m/Y",$date_souscription[$n]);?></small><?php 
			}
			echo "</td><td align='right'>";
					echo number_format($tab_option[$n][$i]['prix'],2);
			echo "</td></tr>";
					}
			}
			
			//Affichage des Options mois plein
			if(date("m/Y",$date_souscription[$n]) == date("m/Y",$debut_mois_prec) and $facture_faite[$n]==0)
			{
				if(isset($tab_option[$n]))
				{
				for($i=0;$i<count($tab_option[$n]);$i++)
						{
				echo "<tr><td>";
				if($tab_option[$n][$i]['reduction'])
				{
					echo $tab_option[$n][$i]['nom']." ".date("m/Y")." (-".$tab_option[$n][$i]['reduction']."%)";
				}else{
					echo $tab_option[$n][$i]['nom']." ".date("m/Y");
				}
				echo "</td><td align='right'>";
						echo number_format($tab_option[$n][$i]['plein'],2);
				echo "</td></tr>";
						}
				}
			}
?>
        </table>
        
        
<?php 	if(!$facture_total_HF){$facture_total_HF=array();}
		//if($facture_HF)
		//{	
			echo "<br><b>Consommations :</b><br><br>";
?>
		<table width="500" align="left" >
        <tr>
        <td width="200"><b>Type</b></td>
        <td width="100" align="center"><b>Quantit&eacute;</b></td>
        <td width="100" align="center"><b>Hors Forfait</b></td>
        <td width="100" align="right"><b>Montant € HT</b></td>
        </tr>
<?php 			
			//Affichage détail
			if(isset($facture_HF[$n]['appels_duree'])){
			echo "<tr><td>";	
			echo "Appels voix ";
				if($reduction_minute_national[$n])
					{
						echo " (-".$reduction_minute_national[$n].")%";
					}
			echo "</td><td align='center'>";
			echo $facture_HF[$n]['appels_duree'];
			echo "</td><td align='center'>";
				if(isset($facture_HF[$n]['appels_hors_forfait_duree'])){
				echo $facture_HF[$n]['appels_hors_forfait_duree'];
				echo "</td><td align='right'>";
				echo $facture_HF[$n]['appels_hors_forfait_cout'];
					
				}else{
				echo '00:00:00';
				echo "</td><td align='right'>";
				echo '0.00';	
				}
			echo "</td></tr>";	
			}
			
			if(isset($facture_HF[$n]['duree_appels_internes'])){
			echo "<tr><td>";	
			echo "Appels internes";
			echo "</td><td align='center'>";
			echo $facture_HF[$n]['duree_appels_internes'];
			echo "</td><td align='center'>";
				echo '00:00:00';
				echo "</td><td align='right'>";
				echo '0.00';	
			echo "</td></tr>";	
			}
			
			if(isset($facture_HF[$n]['appels_surtaxe_duree'])){
			echo "<tr><td>";
			echo "Appels numéros spéciaux";
			echo "</td><td align='center'>";
			echo $facture_HF[$n]['appels_surtaxe_duree'];
			echo "</td><td align='center'>";
			echo $facture_HF[$n]['appels_surtaxe_duree'];
			echo "</td><td align='right'>";
			echo $facture_HF[$n]['appels_surtaxe_cout'];
			echo "</td></tr>";
			}
			
			if(isset($facture_HF[$n]['sms_q'])){
			echo "<tr><td>";
			echo "SMS";
			echo "</td><td align='center'>";
			echo $facture_HF[$n]['sms_q'];
			echo "</td><td align='center'>";
				if(isset($facture_HF[$n]['sms_hors_forfait_q'])){
			echo $facture_HF[$n]['sms_hors_forfait_q'];
			echo "</td><td align='right'>";
			echo $facture_HF[$n]['sms_hors_forfait_cout'];
				}else{
			echo '0';
			echo "</td><td align='right'>";
			echo '0.00';
				}
			echo "</td></tr>";	
			}
			
			if(isset($facture_HF[$n]['mms_q'])){
			echo "<tr><td>";
			echo "MMS";
			echo "</td><td align='center'>";
			echo $facture_HF[$n]['mms_q'];
			echo "</td><td align='center'>";
				if(isset($facture_HF[$n]['mms_hors_forfait_q'])){
			echo $facture_HF[$n]['mms_hors_forfait_q'];
			echo "</td><td align='right'>";
			echo $facture_HF[$n]['mms_hors_forfait_cout'];
				}else{
			echo '0';
			echo "</td><td align='right'>";
			echo '0.00';
				}
			echo "</td></tr>";
			}
			
			if(isset($facture_HF[$n]['sms_mms_premium_q'])){
			echo "<tr><td>";
			echo "SMS et MMS premium";
			echo "</td><td align='center'>";
			echo $facture_HF[$n]['sms_mms_premium_q'];
			echo "</td><td align='center'>";
			echo $facture_HF[$n]['sms_mms_premium_q'];
			echo "</td><td align='right'>";
			echo $facture_HF[$n]['sms_mms_premium_cout'];
			echo "</td></tr>";
			}
			
			if(isset($facture_HF[$n]['sms_mms_premium_recu_q'])){
			echo "<tr><td>";
			echo "SMS et MMS premium re&ccedil;u";
			echo "</td><td align='center'>";
			echo $facture_HF[$n]['sms_mms_premium_recu_q'];
			echo "</td><td align='center'>";
			echo $facture_HF[$n]['sms_mms_premium_recu_q'];
			echo "</td><td align='right'>";
			echo $facture_HF[$n]['sms_mms_premium_recu_cout'];
			echo "</td></tr>";
			}
			
			if(isset($facture_HF[$n]['sms_international_cout'])){
			echo "<tr><td>";
			echo "SMS à l'international";
			echo "</td><td align='center'>";
			echo $facture_HF[$n]['sms_international_q'];
			echo "</td><td align='center'>";
			echo $facture_HF[$n]['sms_international_q'];
			echo "</td><td align='right'>";
			echo $facture_HF[$n]['sms_international_cout'];
			echo "</td></tr>";
			}
			
			if(isset($facture_HF[$n]['mms_international_cout'])){
			echo "<tr><td>";
			echo "MMS à l'international";
			echo "</td><td align='center'>";
			echo $facture_HF[$n]['mms_international_q'];
			echo "</td><td align='center'>";
			echo $facture_HF[$n]['mms_international_q'];
			echo "</td><td align='right'>";
			echo $facture_HF[$n]['mms_international_cout'];
			echo "</td></tr>";
			}
			
			
			if(isset($facture_HF[$n]['data_q'])){
			echo "<tr><td>";
			echo "DATA";
			echo "</td><td align='center'>";
			echo $facture_HF[$n]['data_q'];
			echo "</td><td align='center'>";
				if(isset($facture_HF[$n]['data_hors_forfait_q'])){ 
			echo $facture_HF[$n]['data_hors_forfait_q'];
			echo "</td><td align='right'>";
			echo $facture_HF[$n]['data_hors_forfait_cout'];
				}else{
			echo '0';
			echo "</td><td align='right'>";
			echo '0.00';
				}
			echo "</td></tr>";
			}
			
			if(isset($facture_HF[$n]['appels_international'])){
			echo "<tr><td>";
			echo "Appels à l'international";
			if($reduction_minute_international[$n])
					{
						echo " (-".$reduction_minute_international[$n].")%";
					}
			echo "</td><td align='center'>";
			echo $facture_HF[$n]['appels_international_q'];
			echo "</td><td align='center'>";
			echo $facture_HF[$n]['appels_international_q'];
			echo "</td><td align='right'>";
			echo $facture_HF[$n]['appels_international'];
			echo "</td></tr>";
			}

			if(isset($facture_HF[$n]['roaming_international_cout'])){
			echo "<tr><td>";
			echo "Roaming International";
			echo "</td><td align='center'>";
			echo $facture_HF[$n]['roaming_international_duree'];
			echo "</td><td align='center'>";
			echo $facture_HF[$n]['roaming_international_duree'];
			echo "</td><td align='right'>";
			echo $facture_HF[$n]['roaming_international_cout'];
			echo "</td></tr>";
			}
			
			if(isset($facture_HF[$n]['RFC_duree'])){
			echo "<tr><td>";
			echo "Appel transferé en Roaming";
			echo "</td><td align='center'>";
			echo $facture_HF[$n]['RFC_duree'];
			echo "</td><td align='center'>";
			echo $facture_HF[$n]['RFC_duree'];
			echo "</td><td align='right'>";
			echo $facture_HF[$n]['RFC_cout'];
			echo "</td></tr>";
			}
			
			if(isset($facture_HF[$n]['RTC_duree'])){
			echo "<tr><td>";
			echo "Appel reçu en Roaming";
			echo "</td><td align='center'>";
			echo $facture_HF[$n]['RTC_duree'];
			echo "</td><td align='center'>";
			echo $facture_HF[$n]['RTC_duree'];
			echo "</td><td align='right'>";
			echo $facture_HF[$n]['RTC_cout'];
			echo "</td></tr>";
			}
			
			if(isset($facture_HF[$n]['sms_roaming_cout'])){
			echo "<tr><td>";
			echo "SMS en Roaming ";
			echo "</td><td align='center'>";
			echo $facture_HF[$n]['sms_roaming_q'];
			echo "</td><td align='center'>";
			echo $facture_HF[$n]['sms_roaming_q'];
			echo "</td><td align='right'>";
			echo $facture_HF[$n]['sms_roaming_cout'];
			echo "</td></tr>";
			}
			
			if(isset($facture_HF[$n]['mms_roaming_cout'])){
			echo "<tr><td>";
			echo "MMS en Roaming ";
			echo "</td><td align='center'>";
			echo $facture_HF[$n]['mms_roaming_q'];
			echo "</td><td align='center'>";
			echo $facture_HF[$n]['mms_roaming_q'];
			echo "</td><td align='right'>";
			echo $facture_HF[$n]['mms_roaming_cout'];
			echo "</td></tr>";
			}
			
			if(isset($facture_HF[$n]['data_roaming_cout'])){
			echo "<tr><td>";
			echo "DATA en Roaming ";
			echo "</td><td align='center'>";
			echo $facture_HF[$n]['data_roaming_q']." Mo";
			echo "</td><td align='center'>";
			echo $facture_HF[$n]['data_roaming_q']." Mo";
			echo "</td><td align='right'>";
			echo $facture_HF[$n]['data_roaming_cout'];
			echo "</td></tr>";
			}
			
			if(isset($facture_HF[$n]['messagerie'])){
			echo "<tr><td>";
			echo "Appels Messagerie";
			echo "</td><td align='center'>";
			echo $facture_HF[$n]['messagerie'];
			echo "</td><td align='center'>";
			echo "0";
			echo "</td><td align='right'>";
			echo number_format("0",2);
			echo "</td></tr>";
			}
			?> 
            </table>
			<?php
		//}
		//echo "t1: ".$total_forfait_options."<br>";
		//echo "t2: ".$tab_facture_total_HF."<br>";
		 ?>
		
            <table width='500'>			
            <?php 
			//Affichage du sous total
			echo "<tr><td align='right' width='200'><b>Total services et consommations HT</b></td><td align='right' width='100'>";
			echo "</td><td align='center' width='100'>";
			echo "</td><td align='right' width='100'>";
			echo "<b>".number_format($total_forfait_options[$n]+ $tab_facture_total_HF[$n],2)."</b>" ;
			echo "</td></tr>";
			?>
            </table>
            <br />
				<hr style="height: 2px; color: #666666; background-color: #000000; width: 80%; border: none;">
            <br />
		 
		 <?php
	}		
?><br />
         
        
